library MyKu4;

//单继承+接口多实现
abstract class Vehicle {}

abstract class MotorVehicle extends Vehicle {}

abstract class NonMotorVehicle extends Vehicle {}

//将各自的能力抽成独立的接口，这样的好处就是可以从抽象角度对不同的实现类赋予不同接口能力，
// 职责更加清晰,但是这个只是一方面的问题，它还是无法解决相同能力实现代码冗余的问题
abstract class PetrolDriven {
  void petrolDriven();
}

abstract class PassengerService {
  void passengerService();
}

abstract class CargoService {
  void carryCargo();
}

abstract class ElectricalDriven {
  void electricalDriven();
}

//对于Motor赋予了PetrolDriven、PassengerService、CargoService能力
class Motor extends MotorVehicle implements PetrolDriven, PassengerService, CargoService {
  @override
  void carryCargo() => print('载货'); //仍然需要重写carryCargo

  @override
  void passengerService() => print('载人'); //仍然需要重写passengerService

  @override
  void petrolDriven() => print("汽油驱动"); //仍然需要重写petrolDriven
}

//对于Bus赋予了PetrolDriven、ElectricalDriven、PassengerService能力
class Bus extends MotorVehicle implements PetrolDriven, ElectricalDriven, PassengerService {
  @override
  void electricalDriven() => print("电能驱动"); //仍然需要重写electricalDriven

  @override
  void passengerService() => print('载人'); //仍然需要重写passengerService

  @override
  void petrolDriven() => print("汽油驱动"); //仍然需要重写petrolDriven
}

//对于Truck赋予了PetrolDriven、CargoService能力
class Truck extends MotorVehicle implements PetrolDriven, CargoService {
  @override
  void carryCargo() => print('载货'); //仍然需要重写carryCargo

  @override
  void petrolDriven() => print("汽油驱动"); //仍然需要重写petrolDriven
}

//对于Bicycle赋予了ElectricalDriven、PassengerService能力
class Bicycle extends NonMotorVehicle implements ElectricalDriven, PassengerService {
  @override
  void electricalDriven() => print("电能驱动"); //仍然需要重写electricalDriven

  @override
  void passengerService() => print('载人'); //仍然需要重写passengerService
}

//对于Bike赋予了PassengerService能力
class Bike extends NonMotorVehicle implements PassengerService {
  @override
  void passengerService() => print('载人'); //仍然需要重写passengerService
}
